package com.itheima.dao;

import com.itheima.domain.UserAnnotation;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface UserAnnotationManyDao {


    @Select("select * from user")
    @Results(id = "userMap",value = {
            @Result(id = true, column = "id", property = "userId"),
            @Result(column = "username", property = "userName"),
            @Result(column = "birthday", property = "userBirthday"),
            @Result(column = "sex", property = "userSex"),
            @Result(column = "address", property = "userAddress")
    })
    List<UserAnnotation> findAll();


    /**
     * 一对多
     * @return
     */
    @Select("select * from user")
    @Results(id = "userMap2",value = {
            @Result(id = true, column = "id", property = "userId"),
            @Result(column = "username", property = "userName"),
            @Result(column = "birthday", property = "userBirthday"),
            @Result(column = "sex", property = "userSex"),
            @Result(column = "address", property = "userAddress"),
            @Result(property = "accountList", column = "id", many = @Many(select = "com.itheima.dao.AccountAnnotationDao.findByUid", fetchType = FetchType.EAGER))
    })
    List<UserAnnotation> findAll2();



    @Select("select * from user where id = #{id}")
    @ResultMap(value = {"userMap"})
    UserAnnotation findOne(int id);
}
